home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2361 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  62 lines

  1. Newsgroups: comp.lang.c
  2. Path: Utrecht.NL.net!news
  3. From: E.H.Terwiel@inter.NL.net (E.H. Terwiel (Erik))
  4. Subject: Re: Question on pointer-to-pointer-to-pointer-...
  5. X-Nntp-Posting-Host: utr98-17.utrecht.nl.net
  6. Message-ID: <DLI0p8.H8D@inter.NL.net>
  7. Sender: news@inter.NL.net (News at newsutr)
  8. Organization: NLnet
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <4dq2ej$m3t@cssun.cs.usm.my>
  11. Date: Sat, 20 Jan 1996 21:19:21 GMT
  12.  
  13. bahari@cs.usm.my (Bahari Belaton (Dr)) wrote:
  14.  
  15. >Hi,
  16. >Below is one of the question asked by my student about pointer-to-pointer in
  17. >C - with a specific example on strtod() function. Can anyone help me explain
  18. >this to my student. Especially on the important of pointer-to-pointer.
  19.  
  20. >Thanks
  21.  
  22. >Bahari Belaton
  23.  
  24. >=======================================================================
  25. >Dear All,
  26. >     I hope you can enlighthen me a bit.
  27. >Query 1:
  28. >     According to Deitel, the function prototype for strtod() is:-
  29. >     double strtod(const char *nPtr, char **endPtr) and the function call is
  30. >as follows :-
  31. >     double d;
  32. >     char *string = "51.2% are admitted";
  33. >     char *stringPtr;
  34.  
  35. >     d = strtod(string, &stringPtr);
  36.  
  37. >The book says that &stringPtr is assigned the location of the first character
  38. >after the converted value. How does the function do that?
  39.  
  40. >I'm still confused with **endPtr. Why the **endPtr(pointer to a
  41. >pointer) is used?(What is the significance of using a double pointer? Why
  42. >not just *endPtr since the function assigned the address of first
  43. >character of the string to &stringPtr. (what about***endPtr?
  44. >How many pointers to pointer can we used?)
  45.  
  46. >Thank you very much.
  47. >Your student,
  48. >LEE KENG TUNG csi36864@wira2.cs.usm.my
  49.  
  50. >=================================
  51.  
  52. Well, after using strtod you will want to know where the function
  53. stopped converting. If you would pass the char pointer by VALUE (char
  54. *), the function strtod would remember where it stopped in the pointer
  55. that was put on the stack when calling the function. At returning,
  56. strtod would throw away the copy of stringPTR. And you would not know
  57. where the conversion stopped.
  58. So you pass stringPTR by REFERENCE: &stringPTR. And have strtod
  59. remember where it stopped in the real pointer variable.
  60. Erik
  61.  
  62.